<%@ Page Title="Sys_Config List" Language="C#" AutoEventWireup="true" CodeBehind="Sys_ConfigList.aspx.cs" Inherits="Youz.CreditRepay.Manage.Sys_ConfigList" %>

<script>
    //loadCSS("assets/plugins/gritter/css/jquery.gritter.css");

    var requireJS = [
        //"assets/plugins/gritter/js/jquery.gritter.min.js"
    ];

    loadJS(requireJS);
</script>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading" data-original-title>
                <h2><i class="fa fa-align-justify"></i><span style="font-size: 16px; padding-right: 15px;"><%: R(LanguageModule.Sys_Config, "Sys_Config", "Sys_Config") %></span></h2>
                <div class="panel-actions"></div>
            </div>
            <div class="panel-body">
                <div class="alert alert-danger" style="display: none;">
                    <button type="button" class="close" data-dismiss="alert">×</button><strong><i class="fa fa-warning"></i></strong><span class="content"></span>
                </div>
                <form class="form-inline">
                    <div class="form-group">
                        <label class="control-label" for="RoleDesc"><%: R(LanguageModule.Sys_Config, "ConfigKey", "配置Key") %>：</label>
                        <input type="email" id="ConfigKey" maxlength="45" name="ConfigKey" class="form-control" placeholder="<%: R(LanguageModule.Sys_Config, "ConfigKey", "配置Key") %>">
                    </div>
                    <button type="button" id="btnQuery" name="btnQuery" class="btn btn-default btn-ar btn-primary">
                        <i class="fa fa-search "></i>
                        <%: R(LanguageModule.M_Common, "Query") %>
                    </button>
                </form>
                <div class="form-group"></div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <a href="#" class="btn btn-info" onclick="loadPage('Sys/Sys_ConfigItem.aspx')"><i class="fa fa-plus"></i>
                            <%: R(LanguageModule.M_Common, "Add") %></a>
                        <a href="#" class="btn btn-info" id="btnEdit"><i class="fa fa-edit "></i>
                            <%: R(LanguageModule.M_Common, "Edit") %></a>
                        <a href="#" class="btn btn-info" id="btnDelete"><i class="fa fa-trash-o "></i>
                            <%: R(LanguageModule.M_Common, "Delete") %></a>
                    </div>
                </div>
                <table id="table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var dt;

    $(function () {

        dt = $('#table').DataTable({
            "pageLength": 200,
            "ajax": {
                "url": 'Sys/Handlers/Sys_ConfigHandler.ashx?type=list',
                "type": "POST",
                "dataSrc": "data",
                "data": function (d) {
                    d.configKey = $('#ConfigKey').val();
                }
            },
            "columns": [
                    { "data": 'RowIndex', "title": "#" },
                    { "data": 'ConfigKey', "title": "<%: R(LanguageModule.Sys_Config, "ConfigKey", "配置Key") %>" },
                    { "data": 'ConfigValue', "title": "<%: R(LanguageModule.Sys_Config, "ConfigValue", "配置Value") %>", render: fText },
                    { "data": 'ConfigType', "title": "<%: R(LanguageModule.Sys_Config, "ConfigType", "配置分类") %>" },
                    { "data": 'Status', "title": "<%: R(LanguageModule.M_Common, "Status", "状态") %>", render: fStatus },
                    { "data": 'IsModify', "title": "<%: R(LanguageModule.Sys_Config, "IsModify", "是否可修改") %>", render: fYesNo },
                    { "data": 'Memo', "title": "<%: R(LanguageModule.Sys_Config, "Memo", "备注") %>" },
                    { "data": 'Creator', "title": "<%: R(LanguageModule.Sys_Config, "Creator", "创建人") %>" },
                    { "data": 'CreateTime', "title": "<%: R(LanguageModule.Sys_Config, "CreateTime", "创建时间") %>" },
<%--                    { "data": 'LastModifier', "title": "<%: R(LanguageModule.Sys_Config, "LastModifier", "最后一次修改人") %>" },--%>
                    { "data": 'LastModifyTime', "title": "<%: R(LanguageModule.Sys_Config, "LastModifyTime", "最后一次修改时间") %>" },

            ]
        });
        
        //delete selected row
        $('#btnDelete').click(function () {
            if ($('#table tbody tr.selected').length > 0) {
                if (!dt.row('.selected').data().IsModify) {
                    $(".alert > .content").html("<%: R(LanguageModule.M_Common, "Unmodifiable","该数据无法修改，请重新选择！") %>");
                    $(".alert").show();
                    return false;
                }
                $('#confirm .btn-primary').unbind('click');
                jconfirm("<%: R(LanguageModule.M_Common, "DeleteConfirm") %>", function () {
                    //console.log(dt.row('.selected').data());
                    $.post("Sys/Handlers/Sys_ConfigHandler.ashx?type=delete", { ConfigKey: dt.row('.selected').data().ConfigKey }, function (data) {
                        if (data) {
                            if (data.isSuccess) {
                                dt.ajax.reload();

                                $.gritter.add({
                                    title: '<%: R(LanguageModule.M_Common, "TipSuccess") %>',
                                    text: data.message,
                                    class_name: 'gritter-success'
                                });

                                $('#table tbody tr.selected').remove();
                            }
                            else {
                                $(".alert > .content").html(data.message);
                                $(".alert").show();
                            }
                        }
                    }, "json");
                });
            }
            else {
                $(".alert > .content").html("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
                $(".alert").show();
            }
        });

        //delete selected row
        $('#btnEdit').click(function () {
            if ($('#table tbody tr.selected').length > 0) {
                if (!dt.row('.selected').data().IsModify) {
                    $(".alert > .content").html("<%: R(LanguageModule.M_Common, "Unmodifiable","该数据无法修改，请重新选择！") %>");
                    $(".alert").show();
                    return false;
                }
                loadPage("Sys/Sys_ConfigItem.aspx?ConfigKey=" + dt.row('.selected').data().ConfigKey);
            }
            else {
                $(".alert > .content").html("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
                $(".alert").show();
            }
        });
        $('#btnQuery').click(function () {
            dt.ajax.reload();
        });
    });
    function fnumber(value, row) {

        return value == '1' ? '<span style="color:green"><%=R(LanguageModule.M_Common, "Enable", "啟用") %></span>' : '<span style="color:red"><%=R(LanguageModule.M_Common, "Disable", "禁用") %></span>';

    }
</script>
